package com.hackerrank.contests.oct13.challenges.chocolatefeast;

import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			int N = in.nextInt(), C = in.nextInt(), M = in.nextInt(), tnc = N / C, rcc = tnc;
			while(rcc >= M) {
				int nc = rcc / M;
				tnc += nc;
				rcc = rcc % M + nc;
			}
			System.out.println(tnc);
		}
	}
}
